//
//  AppPrebookButton.swift
//  XWHAOfflineFitting
//
//  Created by edy on 2024/4/24.
//

import UIKit

class AppPrebookButton: UIButton {
    
    lazy var countLb = UILabel()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        addSubview(countLb)
        
        titleLabel?.textAlignment = .center
        countLb.textAlignment = .center
    }
    
    convenience init(type buttonType: UIButton.ButtonType) {
        self.init()
    }
    
    init() {
        super.init(frame: .zero)
        addSubview(countLb)
        
        titleLabel?.textAlignment = .center
        countLb.textAlignment = .center
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
//        contentEdgeInsets
        guard let titleLb = titleLabel else {
            return
        }
        let tLbHeight: CGFloat = 24
        var tFrame: CGRect
        var yOffset: CGFloat = contentEdgeInsets.top
        let xOffset: CGFloat = contentEdgeInsets.left
        let tWidth: CGFloat = bounds.width - xOffset - contentEdgeInsets.right
        yOffset = bounds.center.y - tLbHeight
        tFrame = CGRect(x: xOffset, y: yOffset, width: tWidth, height: tLbHeight)
        titleLb.frame = tFrame
        
        yOffset = tFrame.maxY + 2
        tFrame = CGRect(x: xOffset, y: yOffset, width: tWidth, height: tLbHeight)
        countLb.frame = tFrame
    }

}
